package com.itcam.jyuoop;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class SheetGEN {

    int sheetCount = 30; // 算式个数，默认为30

    int columnCount = 2; // 栏数，默认为2

    int firstOper[]; // 第一个运算数

    int secondOper[]; // 第二个运算数

    char op[]; // 运算符

    // 构造方法
    public SheetGEN() {
        firstOper = new int[sheetCount];
        secondOper = new int[sheetCount];
        op = new char[sheetCount];
    }

    // 生成算术运算式的方法
    public void generateMathExercises() {
        Random random = new Random();
        for (int i = 0; i < sheetCount; i++) {
            int num1 = random.nextInt(101);
            int num2 = random.nextInt(101);
            char operator = random.nextBoolean() ? '+' : '-';
            if (operator == '-' && num1 < num2) {
                i--;
                continue;
            }
            firstOper[i] = num1;
            secondOper[i] = num2;
            op[i] = operator;
        }
    }

    // 打印算术运算式的方法
    public void printMathExercises() {
        for (int i = 0; i < sheetCount; i++) {
            System.out.print(firstOper[i] + " " + op[i] + " " + secondOper[i] + " = "+ "\t");
            if (i % columnCount == 1) {
                System.out.println();
            }
        }
    }

    public static void main(String[] args) {
        SheetGEN sheetGEN = new SheetGEN();
        sheetGEN.generateMathExercises();
        sheetGEN.printMathExercises();

    }



}